String =Yacon.apply(String,{	
	
	
	valid:function (str) 
	{
		var str= str+"";
		if (str=="undefined" || str=="null")
		{
			return "";
		}else
		{
			return str;
		}
	},
	
	contains :function (subStr) 
	{
	    return (this.indexOf(subStr) > -1);
	},

	startsWith:function (subStr) 
	{
	    return (this.substr(0, subStr.length) ==subStr);
	},
	
	endWith:function(subStr){
		return (this.substr(this.length-subStr.length, subStr.length) ==subStr);
	},
	
	search:function(){
		var idx = this.indexOf("?");
		var len = this.length - idx;
		return (this.substr(idx,len));
	},

	trim:function () 
	{	
	    return this.replace(/(^\s*)|(\s*$)/g, "");
	},

	ltrim :function () 
	{
	    return this.replace(/^\s*/g, "");
	},

	rtrim :function () 
	{
	    return this.replace(/\s*$/g, "");
	},

	replaceNewLineChars :function (subStr)
	{
	    return this.replace(/\n/g, subStr);
	},
	
	getReplace:function(reStr,plStr)
	{
		reStr = reStr/g;
		return this.replace(reStr, plStr);
	},

	isTrue:function ()
	{
		return (this==true ||this.isEqual("1") ||
			this.isEqual("true") || this.isEqual("T") ||
			this.isEqual("yes") || this.isEqual("on"));
	},
	
	getInt:function()
	{
		var result = parseInt(this);
		if (isNaN(result)){ result = 0;}
		return result;
	},
	
	getFloat:function()
	{
		var result = parseFloat(this);
		if (isNaN(result)){ result = 0;}
		return result;
	},

	isEqual:function(str)
	{
		str = this.valid(str);
		if (this==str){return true;}
		if (this=="" || str==""){ return false;}		
		return (str.toLowerCase()==this.toLowerCase());
	},
	
	getCLength:function()
	{
		 var ascRegexp = /[^\x00-\xFF]/g;
		 return this.replace(ascRegexp, '...').length;	 
	},
	
	subCStr :function(start, length)
	{
		if (length<=0)
			 return this;
		
		var strLen =0;
		var ascRegexp = /[^\x00-\xFF]/g;
		var retStr="";
		for (var i=start;i<this.length;i++)
		{
			if( this.charAt(i).match(ascRegexp))
				strLen = strLen + 3;
			else
				strLen ++;
			
			if (strLen <= length)
				retStr = retStr +this.charAt(i);
			else
				return retStr;				
		}
		
		return retStr;
		
	 },
	
	fillLZero:function(Length)
	{
		var tmp = this ; 
		for (var i= this.length;i<Length;i++){
			tmp = "0" + tmp ;
		}
		return tmp;
	},
	
	encode:function()
	{
		var intLen  = this.length;
		var strOut  ="";
		var strTemp ="";
		var strFlag = "";

		for(var i=0;i<intLen;i++)
		{
			strTemp = this.charCodeAt(i);

			if (strTemp > 255 || strTemp < 0)
			{
				if (strFlag == "")
				{
					strFlag = "*";
					strOut  = strOut+"[*" + strTemp.toString(16).fillLZero(4);
				}
				else if (strFlag == "~")
				{
					strFlag = "*";
					strOut  = strOut + "*" + strTemp.toString(16).fillLZero(4);
				}
				else if (strFlag == "*")
				{
					strOut = strOut + strTemp.toString(16).fillLZero(4);
				}
			}
			else
			{
				if (strTemp < 48 || (strTemp > 57 && strTemp < 65) || (strTemp > 90 && strTemp < 97) || strTemp > 122)
				{
					if (strFlag == "")
					{
						strFlag = "~";
						strOut  = strOut + "[~" + strTemp.toString(16).fillLZero(2);
					}
					else if (strFlag == "*")
					{
						strFlag = "~";
						strOut  = strOut + "~" + strTemp.toString(16).fillLZero(2);
					}
					else if (strFlag == "~")
					{
						strOut = strOut + strTemp.toString(16).fillLZero(2);
					}
				}
				else
				{
					if (strFlag == "*" || strFlag == "~")
					{
						strFlag = "";
						strOut  = strOut + "]" + this.charAt(i);
					}
					else
					{
						strOut = strOut + this.charAt(i);
					}
				}
			}
		}
				
		return strOut ;
	},
	
	decode:function ()
	{
		var intLen  = this.length;
		var strFlag = "";
		var strOut  = "";
		var strTemp = "";
		
		for(var i=0;i<intLen;i++)
		{
			strTemp = this.charAt(i);

			if (strTemp == "[")
			{
				i++;
				strTemp = this.charAt(i);
			}
			if (strTemp == "]")
			{
				strFlag = "";
				continue;
			}
			if (strTemp == "~")
			{
				i++;
				strFlag="~";
			}
			if (strTemp=="*")
			{
				i++;
				strFlag="*";
			}
			switch (strFlag)
			{
				case "~":
				{
					strTemp = this.substring(i,i+2);
					strTemp = parseInt(strTemp,16);
					strTemp = String.fromCharCode(strTemp);
					strOut  = strOut + strTemp;
					i++;
					break;
				}
				case "*":
				{
					strTemp = this.substring(i,i+4);
					if (strTemp.toUpperCase() == "FFFF"){
						i+=4;
						strTemp = this.substring(i,i+4);
					}
					strTemp = parseInt(strTemp,16);
					strTemp = String.fromCharCode(strTemp);
					strOut  = strOut + strTemp;
					i+=3;
					break;
				}
				case "":
				{
					strOut = strOut + strTemp;
					break;
				}
			}
		}
		
		return strOut;
	},
	
	cut:function(exp){
		var begin = this.indexOf(exp);
		return this.substring(begin+1);
	},
	
	replaceAll:function(s1,s2){
		return this.replace(new RegExp(s1,"gm"),s2);
	}
	
});




